package wwl.lsf;

import wwl.lsf.base.ListNode;

/**
 * @Title
 * @Author wangwenliang
 * @Date 2021/6/10
 * @Description
 */
public class 分隔链表 {


    public ListNode fenGe(ListNode head, int x) {


        ListNode smale = new ListNode(0);
        ListNode large = new ListNode(0);
        ListNode smaleHead = smale;
        ListNode largeHead = large;

        while (head != null) {

            int val = head.val;

            if (val < x) {
                smale.next = head;
                smale = head;
            } else {
                large.next = head;
                large = head;
            }
            head = head.next;
        }
        large.next = null;
        smale.next = largeHead.next;
        return smaleHead.next;
    }
}
